﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using CarCrash.Application.Drawing.entities.Forms;

namespace CarCrash.Application.Drawing.entities
{
    public class RoadLine : DrawableEntity
    {
        //ширина тротуара
        private int wigthr;
        private int wigthl;
        //длина дороги
        private int length;
        // переменнае для switch
        private int fg;
        private int rg;
        //ширина полос
        private int wigth_line1;
        private int wigth_line2;
        //цвет и толщина линий разметки
        private Color color;
        private int thickness;
        private Pen pen;

        public int Wigth_line1 
        {
            get { return wigth_line1; }
            set { wigth_line1 = value; }
        }

        public int Wigth_line2
        {
            get { return wigth_line2; }
            set { wigth_line2 = value; }
        }

        public Color Color
        {
            get { return color; }
            set { color = value; pen = new Pen(color, thickness); }
        }

        public int Thickness
        {
            get { return thickness; }
            set { thickness = value; pen = new Pen(color, thickness); }
        }

        public int Rg 
        {
            get { return rg;  }
            set { rg = value; }
        }

        public int Fg 
        {
            get { return fg; }
            set { fg = value; }
        }

        public int Length 
        {
            get { return length; }
            set { length = value; }
        }

        public int Wigthl
        {
            get { return wigthl; }
            set { wigthl = value; }
        }

        public int Wigthr
        {
            get { return wigthr; }
            set { wigthr = value; }
        }

        //задаем цвет тротуара
        SolidBrush darkgrayBrush = new SolidBrush(Color.DarkGray);
        //задаем цвет дороги
        SolidBrush grayBrush = new SolidBrush(Color.Gray);

        public RoadLine()
        {
            //длина дороги, начальное значение
            Length = 50;
            //ширина тротуара, левого и правого
            Wigthr = 1;
            Wigthl = 1;
            //ширина полос, начальные значения
            Wigth_line1 = 3;
            Wigth_line2 = 3;
            //по умолчанию будут белые тонкие линии (линии разметки)
            Color = Color.White;
            Thickness = 2;
            pen = new Pen(Color, Thickness);
        }

        public override void Paint(Graphics g)
        {
            switch (Rg) 
            {
                case 1:
                    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                    break;
            }
            //производим выборку по тому, что нам нужно нарисовать
            //1: главную дорогу + тротуар слева
            //2: главную дорогу + тротуар справа
            //3: главную дорогу + оба тротуара
            //иначе только одна дорога
            //после любого дорожного полотна создаем разметку
            switch (Fg)
            {
                case 1:
                    g.FillRectangle(darkgrayBrush, CorrectBeginX, CorrectBeginY-Wigthl * 10, Length * 10, Wigthl * 10);
                    g.FillRectangle(grayBrush, CorrectBeginX, CorrectBeginY, Length * 10, (Wigth_line1 + Wigth_line2) * 10);
                    //BeginY = CorrectBeginY - Wigthl * 10;
                    EndX = CorrectBeginX + Length * 10;
                    EndY = CorrectBeginY + (Wigth_line1 + Wigth_line2) * 10;
                    g.DrawLine(pen, CorrectBeginX, CorrectBeginY + Wigth_line1 * 10, EndX, EndY - Wigth_line2 * 10);
                    break;
                case 2:
                    g.FillRectangle(grayBrush, CorrectBeginX, CorrectBeginY, Length * 10, (Wigth_line1 + Wigth_line2) * 10);
                    g.FillRectangle(darkgrayBrush, CorrectBeginX, CorrectBeginY + (Wigth_line1 + Wigth_line2) * 10, Length * 10, Wigthr * 10);
                    EndX = CorrectBeginX + Length * 10;
                    EndY = CorrectBeginY + (Wigth_line1 + Wigth_line2) * 10 + Wigthr * 10;
                    g.DrawLine(pen, CorrectBeginX, CorrectBeginY + Wigth_line1 * 10, EndX, EndY - Wigth_line2 * 10 - Wigthr * 10);
                    break;
                case 3:
                    g.FillRectangle(grayBrush, CorrectBeginX, CorrectBeginY, Length * 10, (Wigth_line1 + Wigth_line2) * 10);
                    g.FillRectangle(darkgrayBrush, CorrectBeginX, CorrectBeginY + (Wigth_line1 + Wigth_line2) * 10, Length * 10, Wigthr * 10);
                    g.FillRectangle(darkgrayBrush, CorrectBeginX, CorrectBeginY-Wigthl * 10, Length * 10, Wigthl * 10);
                    //BeginY = CorrectBeginY - Wigthl * 10;
                    EndX = CorrectBeginX + Length * 10;
                    EndY = CorrectBeginY + (Wigth_line1 + Wigth_line2) * 10 + Wigthr * 10;
                    g.DrawLine(pen, CorrectBeginX, CorrectBeginY + Wigth_line1 * 10, EndX, EndY - Wigth_line2 * 10 - Wigthr * 10);
                    break;
                default:
                    g.FillRectangle(grayBrush, CorrectBeginX, CorrectBeginY, Length * 10, (Wigth_line1 + Wigth_line2) * 10);
                    EndX = CorrectBeginX + Length * 10;
                    EndY = CorrectBeginY + (Wigth_line1 + Wigth_line2) * 10;
                    g.DrawLine(pen, CorrectBeginX, CorrectBeginY + Wigth_line1 * 10, EndX, EndY - Wigth_line2 * 10);
                    break;
            }
        }

        public override System.Windows.Forms.Form GetForm()
        {
            return new RoadDialog(this);
        }
    }
}
